package com.lcl.myapiinterface.controller;


import com.lcl.myapiclintsdk.model.User;
import com.lcl.myapiclintsdk.utils.SignUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 555
 * @title: NameController
 * @projectName myapi-interface
 * @description: TODO
 * @date 2023/3/1116:03
 */
@RestController
@RequestMapping("/name")
public class NameController {

    @GetMapping("/get")
    public String getNameByGet(String name){
        return "Get 你的名字是" + name;
    }

    @PostMapping("/post")
    public String getNameByPost(@RequestParam String name){
        return "Post 你的名字是" + name;
    }

    @PostMapping("/user")
    public String getUserNameByPost(@RequestBody User user, HttpServletRequest request){
//        String accessKey = request.getHeader("accessKey");
//        String nonce = request.getHeader("nonce");
//        String timestamp = request.getHeader("timestamp");
//        String sign = request.getHeader("sign");
//        String body = request.getHeader("body");
//
//        if (!accessKey.equals("lcl")){
//            throw new RuntimeException("无权限");
//        }
//        if (Long.parseLong(nonce)>10000){
//            throw new RuntimeException("无权限");
//        }
//        //todo时间和当前时间不超过5分钟
//        if ((System.currentTimeMillis() - Long.valueOf(timestamp))/(1000*60) <= 5){
//            throw new RuntimeException("已超时");
//        }
//        //实际是从数据库查出
//        String serverSign = SignUtils.getSign(body, "abcdefg");
////        if (!accessKey.equals("lcl") || secretKey.equals("abckefg")){
////            throw new RuntimeException("无权限");
////        }
//        if(!sign.equals(serverSign)){
//            throw new RuntimeException("无权限");
//        }

        return "post 用户名是"+ user.getUsername();
    }






}
